#include <bits/stdc++.h>
using namespace std;

#define int long long

inline int read(){
	int x = 0, f = 1;
	char c = getchar();
	for(; c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
	for(; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
	return f * x;
}

const int N = 2e5 + 9;
int a[N], c[N], pre[N];
bool col[N];
int n, ans;

void dfs(int step){
	if(step == n){
		int tmp = 0;
		for(int i = 1; i <= n; i++){
			for(int j = pre[i]; j != -1; j = pre[j]){
				if(col[i] == col[j]){
					tmp += a[i];
				}
				break;
			}
		}
		ans = max(ans, tmp);
	}
	for(int i = step + 1; i <= n; i++){
		col[i] = 1;
		dfs(step + 1);
		col[i] = 0;
		dfs(step + 1);
	}
}

void solve(){
	ans = -1e18;
	n = read();
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		col[i] = 0;
		pre[i] = -1;
	}
	for(int i = 1; i <= n; i++){
		for(int j = i - 1; j >= 1; j--){
			if(a[i] == a[j]){
				pre[i] = j;
				break;
			}
		}
	}
	bool f = 1;
	for(int i = 1; i <= n; i++) if(pre[i] != -1) f = 0;
	if(f) {cout << 0 << endl;return;}
	
	if(n <= 10){dfs(0); cout << ans << endl; return;}
	int cnt = 0;
	for(int i = 1; i <= n; i++) if(pre[i] != -1) cnt += a[i];
	cout << cnt << endl;
}

signed main(){
	freopen("color.in", "r", stdin);
	freopen("color.out", "w", stdout);
	int T; cin >> T;
	while(T--) solve();
	return 0;
}
//freopen
//filename
